import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import QtQuick.Controls.Material 2.1
import Han.Info 1.0
import Han.GetHomeWork 1.0
import Han.QianDao 1.0
Item {
    anchors.centerIn: parent
    ///一系列的网络接口
    Info{
        id:getinfo
        onReceived: {
            var oJson=JSON.parse(str);
            homeTabName.text=oJson.name;
            homeTabClass.text=oJson.cname;
            homeTabGroup.text=oJson.gname;
            homeTabPoint.text=oJson.cj;
            homeTabScore.text=oJson.point;
            indicator.running=false;
        }
    }
    GetHomeWork{
        id:homeworkid
        onReceived: {
            var oJson=JSON.parse(str);
            worktabScore.text= oJson.point;
            worktabAbout.text=oJson.about;
            worktabDate.text=oJson.addtime;
            worktabName.text=oJson.mess;
            worktabSubject.text=oJson.kemu;
        }
    }
    QianDao{
        id:qiandao
        onReceived: {
            indicator.running=false;
            var oJson=JSON.parse(str);
            var code=oJson.code;
            if(code==1)
            {
                dialog.visible=true;
                dialog.title="签到成功"
                dialogcontent.text="签到成功"
            }else
            {
                dialog.visible=true;
                dialog.title="签到失败"
                dialogcontent.text="签到失败，每天只能签到一次"
            }
        }
    }
    ///网络接口结束
    Component.onCompleted: {
        //部件加载完成事件
        getinfo.getUserData(window.stuid);
        homeworkid.dogetHomeWork(window.stuid)
        indicator.running=true;
    }
    TabBar {
         id: bar
         width: parent.width
         Material.background:Material.BlueGrey
         Material.foreground: "#FFFFFF"
         TabButton {
             text: qsTr("主页")
             font.pixelSize: 6*dp
             font.family: "微软雅黑"
             onClicked: getinfo.getUserData(window.stuid)
              Material.background:Material.BlueGrey

         }
         TabButton {
             text: qsTr("签到")
             font.pixelSize: 6*dp
             font.family: "微软雅黑"
         }
         TabButton {
             text: qsTr("作业")
             font.pixelSize: 6*dp
             font.family: "微软雅黑"
         }
         TabButton {
             text: qsTr("其他")
             font.pixelSize: 6*dp
             font.family: "微软雅黑"
         }

     }

     StackLayout {
         width: parent.width
         currentIndex: bar.currentIndex
         anchors.top:bar.bottom
         anchors.left:parent.left
         anchors.right:parent.right

         anchors.bottom: parent.bottom
         Item {
             id: homeTab
             anchors.left:parent.left
             anchors.right:parent.right
             anchors.top:parent.top
             anchors.bottom: parent.bottom
          //   anchors.centerIn: parent
             Rectangle{
                 id:infoForm
                 width:dp*100
                 height:dp*10
                 color:"white"
                 anchors.top:homeTab.top
                 anchors.topMargin: 20*dp
                 anchors.horizontalCenter: homeTab.horizontalCenter
                 anchors.verticalCenter: homeTab.verticalCenter;
                 opacity:0.3
                 z:1
             }
             ColumnLayout{
                 anchors.left:infoForm.left
                 anchors.right:infoForm.right
                 anchors.top:infoForm.top
                  anchors.topMargin: 20*dp
                 spacing: 5*dp
                  z:2
                RowLayout{

                    Label{
                        text:"姓名："
                        font.pixelSize: 6*dp
                         z:2
                    }
                    Label{
                        text:"邱于涵"
                        id:homeTabName
                        font.pixelSize: 6*dp
                         z:2
                    }
                }
                RowLayout{
                    Label{
                        text:"班级:"
                        font.pixelSize: 6*dp
                         z:2
                    }
                    Label{
                        text:"软件1633"
                        id:homeTabClass
                        font.pixelSize: 6*dp
                         z:2
                    }
                }
                RowLayout{
                    Label{
                        text:"小组："
                        font.pixelSize: 6*dp
                         z:2
                    }
                    Label{
                        text:"SW1633BT6"
                          id:homeTabGroup
                        font.pixelSize: 6*dp
                         z:2
                    }
                }
                RowLayout{
                    Label{
                        text:"积分："
                        font.pixelSize: 6*dp
                         z:2
                    }
                    Label{
                        text:"55"
                        id:homeTabScore
                        font.pixelSize: 6*dp
                         z:2
                    }
                }
                RowLayout{
                    Label{
                        text:"平时成绩："
                        font.pixelSize: 6*dp
                         z:2
                    }
                    Label{
                        text:"90"
                        id:homeTabPoint
                        font.pixelSize: 6*dp
                         z:2
                    }
                }
                RowLayout{
                    Button{
                        text:"注销"
                        Layout.preferredWidth: infoForm.width;
                        onClicked: stackview.pop();
                         z:2
                          Material.background:Material.BlueGrey
                          Material.foreground: "#FFFFFF"
                    }
                }
             }
         }
         Item {
             id: discoverTab
             Rectangle{
                 id:signForm
                 width:dp*100
               //  height:dp*10
                 color:"white"
                 anchors.top:discoverTab.top
                 anchors.topMargin: 20*dp
                 anchors.horizontalCenter:discoverTab.horizontalCenter
                 anchors.verticalCenter: discoverTab.verticalCenter;
                 opacity:0.3
                 z:1
             }
             Button{
                text:"开始签到"
                z:2
                Material.elevation: 6
                anchors.top:signForm.top
                anchors.topMargin: 30*dp
                height:15*dp
                width:signForm.width
                font.pixelSize: 5*dp
                anchors.horizontalCenter: signForm.horizontalCenter
                Material.background:Material.BlueGrey
                Material.foreground: "#FFFFFF"
                onClicked: {
                    qiandao.doQianDao(window.stuid)
                    indicator.running=true;
                }

             }
         }

         Item {
             id: worktab
             Rectangle{
                 id:workForm
                 width:dp*100
                 height:dp*10
                 color:"white"
                 anchors.top:worktab.top
                 anchors.topMargin: 20*dp
                 anchors.horizontalCenter:worktab.horizontalCenter
                 anchors.verticalCenter: worktab.verticalCenter;
                 opacity:0.3
                 z:1
             }
             ColumnLayout{
                 anchors.horizontalCenter: worktab.horizontalCenter
                 anchors.top:workForm.top
                  anchors.topMargin: 12*dp;
                 spacing: 5*dp
                z:2
                RowLayout{

                    Label{
                        text:"日期："
                        font.pixelSize: 6*dp
                    }
                    Label{
                        text:"YYYY:MM:DD hh:mm:ss"
                        id:worktabDate
                        font.pixelSize: 6*dp
                    }
                }
                RowLayout{
                    Label{
                        text:"姓名："
                        font.pixelSize: 6*dp
                    }
                    Label{
                        id:worktabName
                        text:"邱于涵"
                        font.pixelSize: 6*dp
                    }
                }
                RowLayout{
                    Label{
                        font.pixelSize: 6*dp
                        text:"科目："
                    }
                    Label{
                        id:worktabSubject
                        font.pixelSize: 6*dp
                        text:"深入.net"
                    }
                }
                RowLayout{
                    Label{
                        font.pixelSize: 6*dp
                        text:"得分："
                    }
                    Label{
                        id:worktabScore
                        font.pixelSize: 6*dp
                        text:"100"
                    }
                }
                RowLayout{
                    Label{
                        font.pixelSize: 6*dp
                        text:"批注："
                    }
                    Label{
                        id:worktabAbout
                        font.pixelSize: 6*dp
                        text:"批注"
                    }
                }
             }
         }
         Item {
             id: otherTab
             anchors.left:parent.left
             anchors.right:parent.right
             anchors.top:parent.top
             anchors.bottom: parent.bottom
              StackView{
               id:otherTabStackView
               anchors.left:parent.left
               anchors.right:parent.right
               anchors.top:parent.top
               anchors.bottom: parent.bottom
               initialItem:Item{
                   anchors.left:parent.left
                   anchors.right:parent.right
                   anchors.top:parent.top
                   anchors.bottom: parent.bottom
                   Rectangle{
                       id:otherForm
                       width:dp*100
                       height:dp*100
                       color:"white"
                       anchors.top:parent.top
                       anchors.topMargin: 20*dp
                       anchors.horizontalCenter:parent.horizontalCenter
                  //     anchors.verticalCenter: parent.verticalCenter;
                       opacity:0.3
                       z:1
                   }
                   ColumnLayout{
                       anchors.horizontalCenter: otherForm.horizontalCenter
                       anchors.top:otherForm.top
                        anchors.topMargin: 12*dp;
                        spacing: dp*4
                        z:2
                         Button{
                             text:"每日答题"
                              font.pixelSize: 6*dp
                              Material.background:Material.BlueGrey
                              Material.foreground: "#FFFFFF"
                               width:signForm.width
                              onClicked: {
                                   otherTabStackView.push("qrc:/answerQ.qml")
                                  }
                                 }
                           Button{
                             text:"修改密码"
                             Material.background:Material.BlueGrey
                             Material.foreground: "#FFFFFF"
                             font.pixelSize: 6*dp
                             width:otherForm.width-6*dp
                                onClicked: {
                                dialog.visible=true;
                                dialog.title="提示：";
                                  dialogcontent.text="这个功能正在制作~";
                         }
                      }
                 }
               }
             }
         }
     }
}
